﻿//-----------------------------------------------------------------------
// <copyright file="PackageHelper.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using FastNET.CleanAct.Common.Repository.Interfaces.DataInterfaces.ManagementEngine;
using FastNET.CleanAct.Common.Repository.Interfaces.Repositories.ManagementEngine;
using Package = FastNET.CleanAct.Client.ManagerEngineData.Entities.Package;

#endregion

namespace FastNET.CleanAct.Testing.Client.ManagerEngineData.Helpers
{
    /// <summary>
    /// Static Unit Test Helper Class for Package Entities
    /// </summary>
    internal static class PackageHelper
    {
        /// <summary>
        /// Creates a completely random and unique Package Type
        /// </summary>
        /// <returns></returns>
        public static string CreateRandomName()
        {
            return Guid.NewGuid().ToString().Replace("-", string.Empty);
        }

        /// <summary>
        /// Creates a completely random and unique Publisher
        /// </summary>
        /// <returns></returns>
        public static string CreateRandomPublisher()
        {
            return Guid.NewGuid().ToString().Replace("-", string.Empty);
        }

        /// <summary>
        /// Creates an IPackageData ready to save to the database
        /// </summary>
        /// <returns>IPackageData with unique default values</returns>
        public static IPackageData Create()
        {
            Package item = new Package();
            Random rnd = new Random();

            item.Name = CreateRandomName();
            item.Publisher = CreateRandomPublisher();
            item.DateCreated = DateTime.UtcNow;
            item.Version = (new Version(rnd.Next(0, 100), rnd.Next(0, 100))).ToString();

            return item;
        }

        /// <summary>
        /// Creates an IPackageData ready pre-saved to the database
        /// </summary>
        /// <returns>IPackageData with unique default values</returns>
        public static IPackageData CreateDB()
        {
            Package item = (Package)Create();

            DBHelper.Provider.GetRepository<IPackageRepository>().Save(item);

            return item;
        }
    }
}
